<?php
namespace c\config;

/**
 * Description of config
 *
 * @author YeFng
 */
class site extends \m\ad
{
    var $auth_m = 'config';
    
    function __construct()
    {
        parent::__construct();
        $this->f = CONFIG_DIR . 'site.php';
    }
    // service info
    function index_si()
    { 
        $this->PU->check($this->auth_m);
        phpinfo();
        die;
    }
    
    
	function index_home()
    {
        $this->PU->check($this->auth_m);
        $config = include $this->f;
		$this->loadTemplate('config/site', array('data'=>$config));
    }
    function index_save()
    {
        $this->PU->check($this->auth_m);
        $p = $_POST;
        $data = array(
            'title' => $p['title'],
            'keywords' => strip_tags(str_replace('"', '', $p['keywords'])),
            'description' => strip_tags(str_replace('"', '',$p['description'])),
            'url'=> str_replace('"', '',$p['url']),
            'COPR' => preg_strip_tags($p['COPR']),
            'companyName'=>strip_tags($p['companyName'])
        );

        // 不能包含 "
        if (isset($p['a_template']))
            $data['a_template'] = rightfulName($p['a_template']);
        if (isset($p['a_style']))
            $data['a_style'] = rightfulName($p['a_style']);
        if (isset($p['f_template']))
            $data['f_template'] = rightfulName($p['f_template']);
        if (isset($p['f_style']))
            $data['f_style'] = rightfulName($p['f_style']);
       
        
        
        if ($p['int'])
            foreach ($p['int'] as $k=>$v)
             {
                $k = realFunName($k);
                $data[$k] = floatval($v);
             }    
        \log::write('site', 'edit');
        $this->write($data);
    }	
	// save
    function write($data)
    {
        $config = include $this->f;
        $data = array_merge($config, $data);
        $str = var_export($data, true );
        $str = "<?php\nreturn $str;\n?>";
        copy($this->f, $this->f .'.bak');
        $b = file_put_contents($this->f, $str);
        ajax_json(\lang::g ( $b ?'OK': 'save fail'));
    }
}
